import React, { Suspense, useEffect } from 'react';
import { Switch, Route, HashRouter as Router, } from 'react-router-dom';
import { routerList } from 'router/Router';

import { LANGUAGE } from 'utils/localStorageConfig';
import { useTranslation } from 'react-i18next';

import Loading from 'components/Loading/Loading';

import { setSessionItem, getSessionItem } from './Utils/sessionStorage';
import { FrontendAuth } from 'router/FrontendAuth';
import './styles/index.scss'


// import { createBrowserHistory } from "history";
// const history = createBrowserHistory();
function App(props:any) {
  const { i18n } = useTranslation();
  useEffect(() => {
    if (getSessionItem(LANGUAGE)) return
    if (navigator.language === 'zh-CN') {
      setSessionItem(LANGUAGE, 'zn')
      i18n.changeLanguage('zn')
    } else {
      setSessionItem(LANGUAGE, 'en')
      i18n.changeLanguage('en')
    }
  }, [i18n])
  return (
    // <Router history={history}>
    <Router>
      <Switch>
        <Suspense fallback={<Loading />}>
          <Switch>
          <FrontendAuth config={routerList}></FrontendAuth>
            {/* <Route exact path="/" component={Home} />
            {
              routerList.map(item => <Route key={item.path} path={item.path} component={item.component} />)
            } */}
          </Switch>
        </Suspense>
      </Switch>
    </Router>
  );

}

export default App